# = test.forum.7.rb - Forum , Forum PostEdit Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# The functionality for Edit options for Sample Forum Post is tested. 
# 
#
require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'
    
	class TC_ForumPostEdit_test < Test::Unit::TestCase
    
    def startup      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_navigateToForum
      ie.link(:text, 'Forums').click
      
      assert(ie.link(:text, 'Sample Forum').exists?)
      ie.link(:text, 'Sample Forum').click
    end
    
    def test_07_verifyLinksOnForumPage
      assert(ie.link(:text, 'Save').exists?)
      assert(ie.link(:text, 'Cancel').exists?)
      # These are div tags and  not  links  
      assert(ie.div(:id, /ctl00_ctl01$/).exists?)
      assert(ie.div(:id, /ctl03_ctl00_ctl02$/).exists?)
      assert(ie.div(:id, /ctl04_ctl00_ctl01$/).exists?)
      # this is a button
     assert(ie.button(:id, /ctl00_TitleBarSearchButton$/).exists?)
      #assert(ie.link(:id, /ctl00_TitleBarSearchButton$/).exists?)
      assert(ie.link(:text, 'Sample Forum Post').exists?)
      assert(ie.link(:text, 'Last Post').exists?)
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:text, 'More Options').exists?)
    end
    
    def test_08_verifyDropdownListsOnForumPage
      assert(ie.select_list(:id, /TitleBarSearchDropDownList$/).exists?)
      assert(ie.select_list(:id, /SortBy$/).exists?)
      assert(ie.select_list(:id, /SortOrder$/).exists?)
      assert(ie.select_list(:id, /DateFilter$/).exists?)
      assert(ie.select_list(:id, /HideRead$/).exists?)
      assert(ie.select_list(:id, /UserFilter$/).exists?)
      assert(ie.select_list(:id, /Email$/).exists?)
    end
    
    def test_09_verifyCheckBoxesOnForumPage
      assert(ie.checkbox(:name, 'ThreadCheckBox').exists?)
    end
    
    def test_10_verifyButtonsOnForumPage
      assert(ie.button(:id, /ApplyTemp$/).exists?)
      assert(ie.button(:id, /Apply$/).exists?)
      assert(ie.button(:id, /MarkAllRead$/).exists?)
    end
    
    def test_11_verifyFieldsOnForumPage
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
    end
    
    def test_12_selectSampleForumPost
      assert(ie.link(:text, 'Sample Forum Post').exists?)
      ie.link(:text, 'Sample Forum Post').click
     
      assert(ie.contains_text("Sample Forum Post"))
    end
    
    def test_13_verifyLinkButtonsOnForumPostPage
      assert(ie.link(:text, 'Reply').exists?)
      assert(ie.link(:text, 'Report abuse').exists?)
      assert(ie.link(:text, 'Delete').exists?)
      assert(ie.link(:text, 'Edit').exists?)
      assert(ie.link(:text, 'Favorites').exists?)
      assert(ie.link(:text, 'Contact').exists?)
      assert(ie.link(:text, 'Moderate').exists?)
      assert(ie.link(:text, 'Previous').exists?)
      assert(ie.link(:text, 'Next').exists?)
      assert(ie.link(:text, 'Quick Reply').exists?)
    end
    
    def test_14_clickEditPostButton
      ie.link(:text, 'Edit').click
    end
    
    def test_15_verifyLinksOnEditPostPage
      assert(ie.div(:id, /ctl00_ctl01$/).exists?)
      assert(ie.link(:text, 'Save').exists?)
      assert(ie.link(:text, 'Cancel').exists?)
      assert(ie.div(:id, /ctl00_ctl01$/).exists?)
      assert(ie.div(:id, /ctl03_ctl00_ctl02$/).exists?)
      assert(ie.div(:id, /ctl04_ctl00_ctl01$/).exists?)
      # this is a button
      assert(ie.button(:id, /ctl00_TitleBarSearchButton$/).exists?)
      #assert(ie.link(:id, /ctl03_ctl01$/).exists?)
      #assert(ie.link(:id, /ctl04_ctl01$/).exists?)
      #assert(ie.link(:id, /TitleBarSearchButton$/).exists?)
      assert(ie.link(:text, 'Add/Update').exists?)
      assert(ie.link(:id, /RemoveAttachment$/).exists?)
      assert(ie.link(:id, /AddButton$/).exists?)
    end
    
    def test_16_verifyDropDownListsOnEditPostPage
      assert(ie.select_list(:id, /TitleBarSearchDropDownList$/).exists?)
      assert(ie.select_list(:id, /PinnedPost$/).exists?)
    end
    
    #def test_17_verifyRadioButtonsOnEditPostPage
      #~ assert(ie.radio(:id, /PostIcon_0$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_4$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_8$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_11$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_14$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_17$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_20$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_23$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_26$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_29$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_32$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_35$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_38$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_41$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_44$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_47$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_50$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_53$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_1$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_5$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_9$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_12$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_15$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_18$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_21$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_24$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_27$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_30$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_33$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_36$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_39$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_42$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_45$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_48$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_51$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_54$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_2$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_6$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_10$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_13$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_16$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_19$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_22$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_25$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_28$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_31$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_34$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_37$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_40$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_43$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_46$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_49$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_52$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_55$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_3$/).exists?)
      #~ assert(ie.radio(:id, /PostIcon_7$/).exists?) =end 
    #end
    
     
     
    def test_18_verifyCheckBoxesOnEditPostPage
      assert(ie.checkbox(:id, /IsLocked$/).exists?)
      assert(ie.checkbox(:id, /SubscribeToThread$/).exists?)
      assert(ie.checkbox(:id, /IncludeVideo$/).exists?)
      assert(ie.checkbox(:id, /IncludePoll$/).exists?)
    end
    
    def test_19_verifyFieldsAndButtonsOnEditPostPage
      assert(ie.button(:id, /PostButton$/).exists?)
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
      assert(ie.text_field(:id, /PostSubject$/).exists?)
      assert(ie.text_field(:id, /Tags$/).exists?)
      assert(ie.text_field(:id, /VideoUrl$/).exists?)
      assert(ie.text_field(:id, /VideoImageUrl$/).exists?)
      assert(ie.text_field(:id, /VideoDuration$/).exists?)
      assert(ie.text_field(:id, /VideoWidth$/).exists?)
      assert(ie.text_field(:id, /VideoHeight$/).exists?)
      assert(ie.text_field(:id, /PollTitle$/).exists?)
      assert(ie.text_field(:id, /NewAnswer$/).exists?)
      assert(ie.text_field(:id, /ExpireAfterDays$/).exists?)
    end
    
    def test_20_submitPost
      assert(ie.button(:id, /PostButton$/).exists?)
      ie.button(:id, /PostButton$/).click
      assert(ie.contains_text("Sample Forum Post"))
    end
    
  end